home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / delete.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  5KB  |  174 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* delete.c */
  21.  
  22. #include "externs.h"
  23.  
  24.  
  25. void AVL_EDIT_DEL_LEFT(int no)
  26. {
  27.     int i, n;
  28.     char *t;
  29.     AVL_EDIT_WINDOW_PTR w;
  30.     w = &avl_windows[avl_window];
  31.     if (no <= 0) no = 1;
  32.     while (no-- )  {
  33.         n = strlen(t = w -> current_line -> line);
  34.         if (w -> txt_col > 0)  {
  35.             for (i = w -> txt_col - 1; i < n; ++i) 
  36.                 *(t + i) = *(t + i + 1);
  37.             *(t + n - 1) = '\0';
  38.             AVL_CLEAR_LINE();
  39.             if (w -> scr_col == 1)  {
  40.                 w -> offset -= 20;
  41.                 AVL_SCROLL();
  42.                 }
  43.             w -> txt_col -= 1;
  44.             w -> buffer_size -= 1;
  45.             w -> changed = 1;
  46.             AVL_UPDATE_LINE();
  47.             }
  48.         else {  /* Join with the previous line */
  49.             w -> changed = 1;
  50.             w -> offset = 0;
  51.             AVL_JOIN_LEFT();
  52.             }
  53.         }
  54. }
  55.  
  56. void AVL_EDIT_DEL_RIGHT(int no)
  57. {
  58.     int i, n;
  59.     char *t;
  60.     AVL_EDIT_WINDOW_PTR w;
  61.     w = &avl_windows[avl_window];
  62.     if (no <= 0) no = 1;
  63.     while ( no-- )  {
  64.         n = strlen(t = w -> current_line -> line);
  65.         if ((w -> txt_col) < n)  {
  66.             for (i = w -> txt_col; i < n; ++i)
  67.                 *(t + i) = *(t + i + 1);
  68.             *(t + n - 1) = '\0';
  69.             AVL_CLEAR_LINE();
  70.             w -> buffer_size -= 1;
  71.             AVL_UPDATE_LINE();
  72.             w -> changed = 1;
  73.             }
  74.         else   /* Join with the next line */
  75.             AVL_JOIN_RIGHT();
  76.         }
  77. }
  78.  
  79. void AVL_DELETE_LINE()
  80. {
  81.    short left, top, right, bottom;
  82.    struct rccoord rc;
  83.    _gettextwindow( &top, &left, &bottom, &right );
  84.    rc = _gettextposition();
  85.    _settextwindow( rc.row, left, bottom, right );
  86.    _scrolltextwindow( _GSCROLLUP );
  87.    _settextwindow( top, left, bottom, right );
  88.    _settextposition( rc.row, rc.col );
  89. }
  90.  
  91.  
  92.  
  93. void AVL_DO_DEL_LINE()
  94. {
  95.     AVL_EDIT_DEL_LINE(1);
  96. }
  97.  
  98.     
  99. void AVL_REMOVE_CUR_LINE(AVL_LINE_PTR t1)
  100. {
  101.     t1 -> previous -> next = t1 -> next;
  102.     t1 -> next -> previous = t1 -> previous;
  103.     free(t1);
  104. }
  105.  
  106. void AVL_EDIT_DEL_LINE(int no)
  107. {
  108.     AVL_EDIT_WINDOW_PTR w;
  109.     AVL_LINE_PTR t1, temp, temp2;
  110.     struct rccoord old;
  111.     short pos, pos2;
  112.     w = &avl_windows[avl_window];
  113.     if (no <= 0) no = 1;
  114.     while(no--) {
  115.         if (w -> current_line == w -> head)
  116.             return;
  117.         w -> changed = 1;
  118.         t1 = w -> current_line;
  119.         /* Test if last text's line */
  120. /*printf("\nlno = %d current_line = %x next = %x previous = %x head = %x\n",
  121.   w -> current_line -> line_no,    t1, t1 -> next, t1 -> previous, w -> head);
  122. */
  123.         if (t1 -> next == w -> head) {
  124.             AVL_CLEAR_LINE(); 
  125.             if (t1 -> previous != w -> head)
  126.                 AVL_CURSOR_UP(1);
  127.             else {
  128.                 AVL_REMOVE_CUR_LINE(t1);
  129.                 w -> current_line = AVL_MAKE_LINE("",2);
  130.                 AVL_LINK(w -> current_line,w -> head);
  131.                 return;
  132.                 }
  133.             AVL_REMOVE_CUR_LINE(t1);
  134.             continue;
  135.             }
  136.         old = _gettextposition();
  137.         if (w -> scr_row == 1) {
  138.             old = _settextposition(w -> scr_row - 1,1);
  139.             AVL_DELETE_LINE();
  140.             _settextposition(old.row,old.col);
  141.             }
  142.         else if (w -> scr_row < (w -> r2 - w -> r1 + 1)) {
  143.             old = _settextposition(w -> scr_row + 1,1);
  144.             AVL_DELETE_LINE();
  145.             _settextposition(old.row,old.col);
  146.             }
  147.         w -> current_line = t1 -> next;
  148.         AVL_REMOVE_CUR_LINE(t1);
  149.         if (w -> txt_col > strlen(w -> current_line -> line))
  150.             AVL_CURSOR_END();
  151.         pos2 = w -> txt_col;
  152.         pos = w -> scr_row;
  153.         temp = temp2 = w -> current_line;
  154.         /* Go to last screen's line */
  155.         while ((pos < (w -> r2 - w -> r1 + 1)) && (temp -> next != w -> head))    {
  156.             temp = temp -> next;
  157.             ++pos;
  158.             }
  159.         /* Is there text to be displayed in the last screen's line */
  160.         if (pos == (w -> r2 - w -> r1 + 1) && temp != w -> head)  {
  161.             w -> current_line = temp;
  162.             w -> scr_row = w -> r2 - w -> r1 + 1;
  163.             _settextposition( w -> scr_row, 1);
  164.             AVL_UPDATE_LINE();
  165.             }
  166.         w -> current_line = temp2;
  167.         old = _settextposition(w -> scr_row = old.row,w -> scr_col = old.col);
  168.         w -> txt_col = pos2;
  169.         }
  170.     if (w -> current_line != w -> head)
  171.         AVL_MAKE_NUMBER();
  172. }
  173.                 
  174.